home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performCluster.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  18.5 KB  |  680 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  November 25, 1996
  22. //
  23. //  Description:
  24. //      This script provides an option box dialog for the cluster command.
  25. //
  26. //  Input Arguments:
  27. //        boolean showOptionBox    true - show the option box dialog
  28. //                                false - just execute the command
  29. //
  30. //  Return Value:
  31. //      None.
  32. //
  33. //
  34. //  Procedure Name:
  35. //      setOptionVars
  36. //
  37. //  Description:
  38. //        Initialize the option values.
  39. //
  40. //  Input Arguments:
  41. //        Whether to set the options to default values.
  42. //
  43. //  Return Value:
  44. //      None.
  45. //
  46. proc setOptionVars(int $forceFactorySettings)
  47. {
  48.     if ($forceFactorySettings || !`optionVar -exists clusterRelative`) {
  49.         optionVar -intValue clusterRelative 0;
  50.     }
  51.  
  52.     if ($forceFactorySettings || !`optionVar -exists clusterEnvelope`) {
  53.         optionVar -floatValue clusterEnvelope 1.0;
  54.     }
  55.  
  56.     if ($forceFactorySettings || !`optionVar -exists clusterPositioning`) {
  57.         optionVar -stringValue clusterPositioning "default";
  58.     }
  59.     
  60.     if ($forceFactorySettings || !`optionVar -exists clusterExclusive`) {
  61.         // 0 == no exclusive
  62.         // 1 == exclusive with new name
  63.         // 2 == exclusive using an existing partition
  64.         //
  65.         optionVar -intValue clusterExclusive 0;
  66.     }
  67.  
  68.     if ($forceFactorySettings ||
  69.         !`optionVar -exists clusterExclName`) {
  70.         optionVar -stringValue clusterExclName "deformPartition";
  71.     }
  72. }
  73.  
  74. //
  75. //  Procedure Name:
  76. //      clusterSetup
  77. //
  78. //  Description:
  79. //        Update the state of the option box UI to reflect the option values.
  80. //
  81. //  Input Arguments:
  82. //      parent               - Top level parent layout of the option box UI.
  83. //                             Required so that UI object names can be 
  84. //                             successfully resolved.
  85. //
  86. //        forceFactorySettings - Whether the option values should be set to
  87. //                             default values.
  88. //      tabIndex             - 0 = both tabs, 1 = basic, 2 = advanced
  89. //
  90. //  Return Value:
  91. //      None.
  92. //
  93. global proc clusterSetup(string $parent,
  94.                          int $forceFactorySettings,
  95.                          int $tabIndex)
  96. {
  97.     // Retrieve the option settings
  98.     //
  99.     setOptionVars ($forceFactorySettings);
  100.  
  101.     setParent $parent;
  102.  
  103.     // Query the optionVar's and set the values into the controls
  104.  
  105.     if ($tabIndex !=  2) {    
  106.         // Relative mode or not
  107.         int $relative = `optionVar -query clusterRelative`;
  108.         checkBoxGrp -edit -value1 $relative clusterRelativeWidget;
  109.         
  110.         // Overall envelope control
  111.         float $envelope = `optionVar -query clusterEnvelope`;
  112.         floatSliderGrp -edit -value $envelope clusterEnvelopeWidget;
  113.     }
  114.     if ($tabIndex !=  1) {    
  115.         // Positioning of the cluster deformer in the DG
  116.         string $positioning = `optionVar -query clusterPositioning`;
  117.         if (`optionMenuGrp -exists clusterPositioningWidget`) {
  118.             if ($positioning == "default") {
  119.                 optionMenuGrp -edit -select 1 clusterPositioningWidget;
  120.             }
  121.             else if ($positioning == "before") {
  122.                 optionMenuGrp -edit -select 2 clusterPositioningWidget;
  123.             }
  124.             else if ($positioning == "after") {
  125.                 optionMenuGrp -edit -select 3 clusterPositioningWidget;
  126.             }
  127.             else if ($positioning == "split") {
  128.                 optionMenuGrp -edit -select 4 clusterPositioningWidget;
  129.             }
  130.             else if ($positioning == "parallel") {
  131.                 optionMenuGrp -edit -select 5 clusterPositioningWidget;
  132.             }
  133.             else {
  134.                 optionMenuGrp -edit -select 1 clusterPositioningWidget;
  135.             }
  136.         }
  137.         
  138.         int $exc=`optionVar -query clusterExclusive`;
  139.         if (`checkBoxGrp -exists exclWidget`) {
  140.             checkBoxGrp -e -v1 $exc exclWidget;
  141.         }
  142.         string $exn=`optionVar -query clusterExclName`;
  143.         if (`textFieldGrp -exists partitionNameWidget`) {
  144.             textFieldGrp -e -tx $exn -enable $exc partitionNameWidget;
  145.         }
  146.         if (`optionMenuGrp -exists partitionListWidget`) {
  147.             optionMenuGrp -e  -enable $exc partitionListWidget;
  148.         }
  149.     }
  150. }
  151.  
  152. //
  153. //  Procedure Name:
  154. //      clusterCallback
  155. //
  156. //  Description:
  157. //        Update the option values with the current state of the option box UI.
  158. //
  159. //  Input Arguments:
  160. //      parent - Top level parent layout of the option box UI.  Required so
  161. //               that UI object names can be successfully resolved.
  162. //
  163. //        doIt   - Whether the command should execute.
  164. //
  165. //  Return Value:
  166. //      None.
  167. //
  168. global proc clusterCallback(string $parent, int $doIt)
  169. {
  170.     setParent $parent;
  171.  
  172.     // Set the optionVar's from the control values, and then perform the command
  173.  
  174.     // Relative mode or not
  175.     int $relative = `checkBoxGrp -query -value1 clusterRelativeWidget`;
  176.     optionVar -intValue clusterRelative $relative;
  177.  
  178.     // Overall envelope control
  179.     optionVar -floatValue clusterEnvelope `floatSliderGrp -query -value clusterEnvelopeWidget`;
  180.  
  181.     // Positioning of the cluster deformer in the DG
  182.     string $positioning = "default";
  183.     if (`optionMenuGrp -exists clusterPositioningWidget`) {
  184.         if (`optionMenuGrp -query -select clusterPositioningWidget` == 1) {
  185.             $positioning = "default";
  186.         }
  187.         else if (`optionMenuGrp -query -select clusterPositioningWidget` == 2) {
  188.             $positioning = "before";
  189.         }
  190.         else if (`optionMenuGrp -query -select clusterPositioningWidget` == 3) {
  191.             $positioning = "after";
  192.         }
  193.         else if (`optionMenuGrp -query -select clusterPositioningWidget` == 4) {
  194.             $positioning = "split";
  195.         }
  196.         else if (`optionMenuGrp -query -select clusterPositioningWidget` == 5) {
  197.             $positioning = "parallel";
  198.         }
  199.     }
  200.     optionVar -stringValue clusterPositioning $positioning;
  201.  
  202.     if (`checkBoxGrp -exists  exclWidget`) {
  203.         optionVar -intValue clusterExclusive `checkBoxGrp -q -v1 exclWidget`;
  204.     }
  205.     if (`optionMenuGrp -exists partitionListWidget`) {
  206.         string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`;
  207.         if ($partitionNameVal == "Create New Partition") {
  208.             if (`textFieldGrp -exists partitionNameWidget`) {
  209.                 $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`;
  210.             }
  211.         } else {
  212.             // a value of 2 indicates that we use an existing partition
  213.             //
  214.             optionVar -intValue clusterExclusive 2;
  215.         }
  216.         
  217.         optionVar -stringValue clusterExclName $partitionNameVal;
  218.     }
  219.     if ($doIt) {
  220.         performCluster 0; 
  221.         addToRecentCommandQueue "performCluster 0" "Cluster";
  222.     }
  223. }
  224.  
  225.  
  226. //
  227. //  Procedure Name:
  228. //      createClusterTabUI
  229. //
  230. //  Description:
  231. //        This is an example of how to delay the creation of the tab UI.
  232. //        The contents of each tab is created only when it is required,
  233. //        ie. if the tab is initially visible or if the tab is selected
  234. //        by the user.
  235. //
  236. //  Input Arguments:
  237. //      The name of the tab layout.
  238. //
  239. //  Return Value:
  240. //      None.
  241. //
  242. global proc createClusterTabUI(string $tabLayout)
  243. {
  244.     string $tab[] = `tabLayout -query -childArray $tabLayout`;
  245.     int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`;
  246.  
  247.     //    Determine if the UI for this tab has been created yet.
  248.     //    This is accomplished by querying the number of children
  249.     //    in the current tab.  If the tab has no children then the UI
  250.     //    must be created.
  251.     //
  252.     if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) {
  253.  
  254.         setParent $tab[$currentTabIndex-1];
  255.  
  256.         string $label;
  257.         int $index;
  258.  
  259.         //    Activate the default UI template so that the layout of this 
  260.         //    option box is consistent with the layout of the rest of the 
  261.         //    application.
  262.         //
  263.         setUITemplate -pushTemplate DefaultTemplate;
  264.  
  265.         //    Turn on the wait cursor.
  266.         //
  267.         waitCursor -state 1;
  268.  
  269.         //    The current tab has no children.  Determine which tab is
  270.         //    active and create its UI.
  271.         //
  272.         //    RECOMMENDATION:  Use the 'Grp' commands where possible because
  273.         //    they obey the formatting specified in the default template.
  274.         //    This will result in a more consistent look throughout the
  275.         //    application.
  276.         //    
  277.         if (1 == $currentTabIndex) {
  278.             
  279.             //    Create UI for the first tab.
  280.             //
  281.             
  282.             // Relative mode or not
  283.             checkBoxGrp
  284.                 -label "Mode"
  285.                 -label1 "Relative"
  286.                 -numberOfCheckBoxes 1
  287.                 clusterRelativeWidget;
  288.  
  289.             // Overall envelope control
  290.             floatSliderGrp
  291.                 -label "Envelope"
  292.                 -field true
  293.                 -min 0.0 -max 1.0
  294.                 -fmn -10.0 -fmx 10.0
  295.                 -pre 3 clusterEnvelopeWidget;
  296.  
  297.         } else if (2 == $currentTabIndex) {
  298.             
  299.             //    Create UI for the second tab.
  300.             //
  301.  
  302.             // Positioning of the cluster deformer in the DG
  303.             optionMenuGrp -label "Deformation Order" clusterPositioningWidget;
  304.             menuItem -label "Default"       clusterPosItem1;
  305.             menuItem -label "Before"        clusterPosItem2;
  306.             menuItem -label "After"         clusterPosItem3;
  307.             menuItem -label "Split"         clusterPosItem4;
  308.             menuItem -label "Parallel"      clusterPosItem5;
  309.  
  310.             separator;
  311.             checkBoxGrp    
  312.                 -numberOfCheckBoxes 1
  313.                 -label ""
  314.                 -label1 "Exclusive"
  315.                 -v1 0 
  316.                 -on1 "optionMenuGrp -e -enable 1 partitionListWidget; updatePartitionNameWidget;"
  317.                 -offCommand "optionMenuGrp -e -enable 0 partitionListWidget; updatePartitionNameWidget;"
  318.                 exclWidget;
  319.  
  320.     // Create an option menu listing the partitions
  321.     //
  322.             optionMenuGrp -l "Partition to Use" -enable `checkBoxGrp -q -v1 exclWidget`
  323.                 -cc "updatePartitionNameWidget" partitionListWidget;
  324.  
  325.             string $currentNameOption = "";
  326.             if (`optionVar -exists clusterExclName`) {
  327.                 $currentNameOption = `optionVar -q clusterExclName`;
  328.             }
  329.             
  330.             // add all the partitions to the menu
  331.             //
  332.             int $pp;
  333.             string $partitionArray[];
  334.             $partitionArray = `ls -type partition`;
  335.             int $partitionCount = size($partitionArray);
  336.             menuItem -l "Create New Partition";
  337.             for ($pp = 0; $pp < $partitionCount; $pp++)
  338.             {
  339.                 // Do not list the render partition as adding items to
  340.                 // it is only going to cause confusion.
  341.                 //
  342.                 if ($partitionArray[$pp] != "renderPartition" && 
  343.                     $partitionArray[$pp] != "characterPartition") {
  344.                     menuItem -l $partitionArray[$pp];
  345.                 }
  346.                 if ($currentNameOption == $partitionArray[$pp]) {
  347.                     optionVar -stringValue clusterExclName "deformPartition";
  348.                 }
  349.             }
  350.  
  351.             textFieldGrp -l "New Partition Name" -enable `checkBoxGrp -q -v1 exclWidget` 
  352.                 -tx "deformPartition"
  353.                 partitionNameWidget;
  354.         
  355.             updatePartitionNameWidget;
  356.         }
  357.  
  358.         //    Update the control values to match the options.
  359.         //
  360.         eval (("clusterSetup " + $tabLayout + " "+0+" "+$currentTabIndex));
  361.  
  362.         //    Turn off the wait cursor.
  363.         //
  364.         waitCursor -state 0;
  365.         
  366.         //    Deactivate the default UI template.
  367.         //
  368.         setUITemplate -popTemplate;
  369.     }
  370. }
  371.  
  372. //
  373. //  Procedure Name:
  374. //      clusterOptions
  375. //
  376. //  Description:
  377. //        Construct the option box UI.  Involves accessing the standard option
  378. //        box and customizing the UI accordingly.
  379. //
  380. //  Input Arguments:
  381. //      None.
  382. //
  383. //  Return Value:
  384. //      None.
  385. //
  386. proc clusterOptions()
  387. {
  388.     //    Name of the command for this option box.
  389.     //
  390.     string $commandName = "cluster";
  391.  
  392.     //    Build the option box actions.
  393.     //
  394.     string $callback = ($commandName + "Callback");
  395.     string $setup = ($commandName + "Setup");
  396.  
  397.     //    STEP 1:  Get the option box.
  398.     //    ============================
  399.     //
  400.     //  The value returned is the name of the layout to be used as
  401.     //    the parent for the option box UI.
  402.     //
  403.     string $layout = getOptionBox();
  404.     setParent $layout;
  405.     
  406.     //    STEP 2:  Pass the command name to the option box.
  407.     //    =================================================
  408.     //
  409.     //    Any default option box behaviour based on the command name is set 
  410.     //    up with this call.  For example, updating the 'Help' menu item with
  411.     //    the name of the command.
  412.     //
  413.     setOptionBoxCommandName($commandName);
  414.  
  415.     //    STEP 3:  Activate the default UI template.
  416.     //    ==========================================
  417.     //
  418.     //    Activate the default UI template so that the layout of this 
  419.     //    option box is consistent with the layout of the rest of the 
  420.     //    application.
  421.     //
  422.     //    Note: this option box example delays the creation of the UI
  423.     //    until it's required.  Therefore this step is moved to the
  424.     //    procedure where the UI is actually created. 
  425.     //
  426.     //setUITemplate -pushTemplate DefaultTemplate;
  427.  
  428.     //    STEP 4: Create option box contents.
  429.     //    ===================================
  430.     //    
  431.     //    This, of course, will vary from option box to option box.    
  432.     
  433.     //    Demonstrate the delaying of UI creation via tab layouts.
  434.     //    Instead of creating all of the option box UI initially, only
  435.     //    create that which is initially visible.  Wait, until the 
  436.     //    other tabs are selected to create the remaining UI.
  437.     //
  438.     string $tabLayout = `tabLayout -scrollable 1`;
  439.  
  440.     //    Attach an action that will be invoked before a tab is selected.
  441.     //    
  442.     tabLayout -edit 
  443.         -preSelectCommand ("createClusterTabUI " + $tabLayout)
  444.         $tabLayout;
  445.  
  446.     //    Create just the immediate children of the tab layout so that
  447.     //    the tabs appear.
  448.     //
  449.     columnLayout;
  450.         setParent ..;
  451.     columnLayout;
  452.         setParent ..;
  453.     
  454.     //    Set the tab labels.
  455.     //
  456.     tabLayout -edit
  457.         -tabLabelIndex 1 "Basic"
  458.         -tabLabelIndex 2 "Advanced"
  459.         $tabLayout;
  460.  
  461.     //    Create the UI for the tab that is initially visible.
  462.     //
  463.     createClusterTabUI($tabLayout);
  464.  
  465.     //    Step 5: Deactivate the default UI template.
  466.     //  ===========================================
  467.     //
  468.     //    Note: this option box example delays the creation of the UI
  469.     //    until it's required.  Therefore this step is moved to the
  470.     //    procedure where the UI is actually created.
  471.     //
  472.     //    See also Step 2. 
  473.     //
  474.     //setUITemplate -popTemplate;
  475.  
  476.     //    Step 6: Customize the buttons.  
  477.     //    ==============================
  478.     //
  479.     //    Provide more descriptive labels for the buttons.  This is not 
  480.     //    necessary, but in some cases, for example, a button labelled 
  481.     //    'Create' may be more meaningful to the user than one labelled
  482.     //    'Apply'.
  483.     //
  484.     //  Disable those buttons that are not applicable to the option box.
  485.     //
  486.     //    Attach actions to those buttons that are applicable to the option
  487.     //    box.  Note that the 'Close' button has a default action attached 
  488.     //    to it that will hide the window.  If a a custom action is
  489.     //    attached to the 'Close' button then be sure to call the 'hide the
  490.     //    option box' procedure within the custom action so that the option
  491.     //    box is hidden properly.
  492.  
  493.     //    'Apply' button.
  494.     //
  495.     string $applyBtn = getOptionBoxApplyBtn();
  496.     button -edit
  497.         -label "Create"
  498.         -command ($callback + " " + $tabLayout + " " + 1)
  499.         $applyBtn;
  500.  
  501.     //    'Save' button.
  502.     //
  503.     string $saveBtn = getOptionBoxSaveBtn();
  504.     button -edit 
  505.         -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox")
  506.         $saveBtn;
  507.  
  508.     //    'Reset' button.
  509.     //
  510.     string $resetBtn = getOptionBoxResetBtn();
  511.     button -edit 
  512.         -command ($setup + " " + $tabLayout + " " + 1+" "+0)
  513.         $resetBtn;
  514.  
  515.     //    Step 7: Set the option box title.
  516.     //    =================================
  517.     //
  518.     setOptionBoxTitle("Cluster Options");
  519.  
  520.     //    Step 8: Customize the 'Help' menu item text.
  521.     //    ============================================
  522.     //
  523.     setOptionBoxHelpTag( "CreateCluster" );
  524.  
  525.     //    Step 9: Set the current values of the option box.
  526.     //    =================================================
  527.     //
  528.     //    NOTE:  Can not do this here since we do not know what UI is
  529.     //    currently visible.  This is moved to where the UI is created.
  530.     //
  531.     //eval (($setup + " " + $tabLayout + " " + 0));    
  532.     
  533.     //    Step 10: Show the option box.
  534.     //    =============================
  535.     //
  536.     showOptionBox();
  537. }
  538.  
  539. //
  540. //  Procedure Name:
  541. //      clusterHelp
  542. //
  543. //  Description:
  544. //        Return a short description about this command.
  545. //
  546. //  Input Arguments:
  547. //      None.
  548. //
  549. //  Return Value:
  550. //      string.
  551. //
  552. proc string clusterHelp()
  553. {
  554.  
  555.     return 
  556.     "  Command: cluster";    
  557. }
  558.  
  559. //
  560. //  Procedure Name:
  561. //      assembleCmd
  562. //
  563. //  Description:
  564. //        Construct the command that will apply the option box values.
  565. //
  566. //  Input Arguments:
  567. //      None.
  568. //
  569. //  Return Value:
  570. //      None.
  571. //
  572. proc string assembleCmd()
  573. {
  574.     string $cmd;
  575.     
  576.     setOptionVars(false);
  577.  
  578.     $cmd = "newCluster \"";
  579.  
  580.     int $relative = `optionVar -query clusterRelative`;
  581.     float $envelope = `optionVar -query clusterEnvelope`;
  582.     
  583.     string $positioning = `optionVar -query clusterPositioning`;
  584.     
  585.     string $positioningFlag = "";
  586.     if ($positioning != "default")
  587.     {
  588.         $positioningFlag = ("-" + $positioning);
  589.     }
  590.  
  591.     string $cmd;
  592.     $cmd += $positioningFlag;
  593.     
  594.     if ($relative)
  595.         $cmd+= " -relative";
  596.  
  597.     $cmd += (" -envelope " + $envelope);
  598.         
  599.     int $exc=`optionVar -query clusterExclusive`;
  600.     if ($exc) {
  601.         string $exn=`optionVar -query clusterExclName`;
  602.         if ($exn!="") {
  603.             // make sure that we do not clash names with an existing
  604.             // partition when the user requested a new partition, even
  605.             // if the user may have entered a non-unique name
  606.             //
  607.             if ($exc == 1)     $exn += "#";
  608.             //$cmd += (" -exclusive \"" + $exn+"\"");
  609.             $cmd += (" -exclusive \\\"" + $exn+"\\\"");
  610.         }
  611.     }
  612.     $cmd += "\";";
  613.  
  614.     return $cmd;
  615. }
  616.  
  617. //
  618. //  Procedure Name:
  619. //      performCluster
  620. //
  621. //  Description:
  622. //        Perform the cluster command using the corresponding 
  623. //        option values.  This procedure will also show the option box
  624. //        window if necessary as well as construct the command string
  625. //        that will invoke the cluster command with the current
  626. //        option box values.
  627. //
  628. //  Input Arguments:
  629. //      0 - Execute the command.
  630. //      1 - Show the option box dialog.
  631. //      2 - Return the command.
  632. //
  633. //  Return Value:
  634. //      None.
  635. //
  636. global proc string performCluster(int $action)
  637. {
  638.     string $cmd = "";
  639.  
  640.     switch ($action) {
  641.  
  642.         //    Execute the command.
  643.         //
  644.         case 0:
  645.             //    Retrieve the option settings
  646.             //
  647.             setOptionVars(false);
  648.  
  649.             //    Get the command.
  650.             //
  651.             $cmd = `assembleCmd`;
  652.  
  653.             //    Execute the command with the option settings.
  654.             //
  655.             evalEcho($cmd);
  656.  
  657.             break;
  658.  
  659.         //    Show the option box.
  660.         //
  661.         case 1:
  662.             clusterOptions;
  663.             break;
  664.  
  665.         //    Return the command string.
  666.         //
  667.         case 2:
  668.             //    Retrieve the option settings.
  669.             //
  670.             setOptionVars (false);
  671.  
  672.             //    Get the command.
  673.             //
  674.             $cmd = `assembleCmd`;
  675.             break;
  676.     }
  677.     return $cmd;
  678. }
  679.  
  680.